$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'cgs/cgsaccidencheck/list',
        datatype: "json",
        colModel: [			
			{ label: 'id', name: 'id', index: 'id', width: 50, key: true,hidden:true },
			{ label: '申请用户', name: 'applyUserId', index: 'apply_user_id', width: 80,hidden:true },
			{ label: '用户姓名', name: 'userName', index: 'user_name', width: 80 }, 			
			{ label: '联系方式', name: 'mobile', index: 'mobile', width: 80 }, 			
			{ label: '身份证号', name: 'idCardNum', index: 'id_card_num', width: 80,hidden:true },
			{ label: '车辆类型', name: 'vehicleType', index: 'vehicle_type', width: 80,formatter:function(value,options,row){
                return dictJudge(value, vm.hpzl);
            } },
			{ label: '车牌号码', name: 'vehicleNum', index: 'vehicle_num', width: 80 }, 			
			{ label: '事故发生时间', name: 'accidentTime', index: 'accident_time', width: 80 },
			{ label: '事故认定书领取时间', name: 'accidentFileTime', index: 'accident_file_time', width: 80,hidden:true },
			{ label: '邮寄地址', name: 'postAddress', index: 'post_address', width: 80 },
			{ label: '办理状态', name: 'status', index: 'status', width: 80 ,formatter:function(value,options,row){
               return dictJudge(value, vm.status);
            }},
			{ label: '受理快递单号', name: 'acceptExpressNo', index: 'accept_express_no', width: 80 },
			{ label: '申请时间', name: 'createTime', index: 'create_time', width: 80 }
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		cgsAccidencheck: {},
        hpzl:[],
        status:[],
        lingqu:[],
        shenpi:{'status':'2',}
	},
    created:function(){
        $.get(baseURL+"/sys/dict/select/plateNumberType,accident_check_status,getResultMethod",function (data) {
            vm.hpzl = data.dict.plateNumberType;
            vm.status = data.dict.accident_check_status;
            vm.lingqu = data.dict.getResultMethod;
        });
    },
	methods: {
		query: function () {
			vm.reload();
		},
		look: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "详情/办理";
            
            vm.getInfo(id)
		},
        executeAudit: function () {
			var url = "cgs/cgsaccidencheck/update";
			if(vm.shenpi.status === '3' && $.isEmptyObject(vm.shenpi.notAcceptReason)){
                alert("请填写不受理事由");
                return ;
            }
            vm.shenpi.id=vm.cgsAccidencheck.id;
            vm.shenpi.acceptTime = dateFtt('yyyy-MM-dd hh:mm:ss',new Date());
			$.ajax({
				type: "POST",
			    url: baseURL + url,
                contentType: "application/json",
			    data: JSON.stringify(vm.shenpi),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
                            $("#cgsaccidentcheckModal").modal('hide');
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
        banjie:function(){
            if($.isEmptyObject(vm.shenpi.acceptExpressNo)){
                alert("请填写快递单号");
                return ;
            }
            vm.shenpi.status = '4';
            vm.shenpi.id=vm.cgsAccidencheck.id;
            var url = "cgs/cgsaccidencheck/update";
            $.ajax({
                type: "POST",
                url: baseURL + url,
                contentType: "application/json",
                data: JSON.stringify(vm.shenpi),
                success: function(r){
                    if(r.code === 0){
                        alert('操作成功', function(index){
                            vm.reload();
                            $("#cgsaccidentcheckBjModal").modal('hide');
                        });
                    }else{
                        alert(r.msg);
                    }
                }
            });
        },
		getInfo: function(id){
			$.get(baseURL + "cgs/cgsaccidencheck/info/"+id, function(r){
                vm.cgsAccidencheck = r.cgsAccidencheck;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		}
	}
});